import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:ls_work/net/api/http_api.dart';
import 'package:ls_work/util/ext_utils.dart';
import 'package:ls_work/viewmodel/new_activity/activity_recommend_list_view_model.dart';
import 'package:ls_work/util/ext_utils.dart';
import 'activity_info_detail_page.dart';

class ActivityRecommendListPage extends BaseStatefulMvvmWidget {
  @override
  State<StatefulWidget> createState() => _ActivityRecommendListState();
}

class _ActivityRecommendListState extends BaseMvvmListState<
    ActivityRecommendListViewModel, ActivityRecommendListPage> {
  @override
  Widget buildRootView(BuildContext context, Widget loadingContentWidget) {
    return Scaffold(
      backgroundColor: Colors.grey[200],
      appBar: AppBar(
        title: Text("活动推荐"),
      ),
      body: Column(
        children: [
          Row(
            children: [
              Icon(Icons.search,color: Colors.grey,),
              Container(width: 8,),
              CommonInput(
                hintText: '活动名称',
                border: InputBorder.none,
                isDense: true,
                padding: EdgeInsets.zero,
                keyboardType: CommonInputType.text,
                textInputAction: TextInputAction.search,
                onChanged: (str){
                  viewModel.searchInput = str;
                },
                onSubmitted: (str){
                  viewModel.requestRefresh();
                },
              ).setWeight(1)
            ],
          ).addToContainer(
            decoration: BoxDecoration(
              color: Colors.grey[200],
              borderRadius: 20.borderRadius,
            ),
            padding: EdgeInsets.symmetric(horizontal: 10,vertical: 10)
          ).addToContainer(
              color: Colors.white,
              padding: EdgeInsets.symmetric(horizontal: 16, vertical: 8)),
          loadingContentWidget.setWeight(1)
        ],
      ),
    );
  }

  @override
  Widget createItemWidget(int index) {
    var item = viewModel.listItems[index];
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        AspectRatio(
          aspectRatio: 2,
          child: Stack(
            children: [
              ImageLoad(
                "${HttpApi.imageHead}${item.attachId}",
                fit: BoxFit.cover,
                width: MediaQuery.of(context).size.width,
              ).toRound(borderRadius: BorderRadius.vertical(top: 10.radius)),

              CommonText('${item.activityTypeName}',textColor: Colors.white,textSize: 14).addToContainer(
                padding: EdgeInsets.symmetric(horizontal: 10,vertical: 5),
                decoration: BoxDecoration(
                  color: Colors.redAccent,
                  borderRadius: BorderRadius.only(topRight: 15.radius,bottomRight: 15.radius)
                )
              ).setLocation(top: 15,left: 0)
            ],
          ),
        ),
        Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Container(height: 10,),
            Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                CommonText("${item.activityName}",textSize: 17,fontWeight: FontWeight.bold).setWeight(1),
                Container(width: 10,),
                CommonText('${item.statusName}',textColor: Colors.green)
              ],
            ),
            Container(height: 10,),
            CommonText("${item.activityContent}"),
            Container(height: 10,),
            Row(
              children: [
                CommonText("报名时间："),
                CommonText("${item.enrollStartTime?.changeTime(format:['mm','/','dd',' ',HH,':',nn])}-${item.enrollEndTime?.changeTime(format:['mm','/','dd',' ',HH,':',nn])}").setWeight(1)
              ],
            ),
            Container(height: 10,),
            Row(
              children: [
                CommonText("活动时间："),
                CommonText("${item.activityStartTime?.changeTime(format:['mm','/','dd',' ',HH,':',nn])}-${item.activityEndTime?.changeTime(format:['mm','/','dd',' ',HH,':',nn])}")
              ],
            ),
            Container(height: 10,),
            Row(
              children: [
                CommonText('签到积分：${item.checkPoints}',textColor: Colors.green),
                Container(width: 10,),
                CommonText('志愿者积分：${item.volunteerPoints}',textColor: Colors.green),
                Container().setWeight(1),
                CommonText("${item.regHumanCount}人参加")
              ],
            ),
            Container(height: 10,),
          ],
        ).addToContainer(
          margin: EdgeInsets.symmetric(horizontal: 15)
        )

      ],
    ).onTap(() {
      Go().push(ActivityInfoDetailPage(item));
    }).addToContainer(margin: EdgeInsets.symmetric(horizontal: 16),decoration: BoxDecoration(
      color: Colors.white,
      borderRadius: 10.borderRadius
    ));
  }

  @override
  EdgeInsets get listPadding => EdgeInsets.symmetric(vertical: 10);

  @override
  Widget get separatorDivider => Container(height: 10,);

  @override
  ActivityRecommendListViewModel createViewModel() {
    return ActivityRecommendListViewModel(context);
  }

  @override
  bool get canPullUp => true;
}
